from LAC import LAC
from ddparser import DDParser
lac = LAC(mode="lac")
ddp = DDParser()

def sent_ident(sent):
    lacres = lac.run(sent)
    ddpres = ddp.parse_seg([lacres[0]])
    print(ddpres)
    print(lacres)
    hednum = -1
    for i in range(len(ddpres[0]["deprel"])):
        if ddpres[0]["deprel"][i] == "HED":
            hednum = i + 1
    if "，" not in sent:
        for i in range(len(ddpres[0]["deprel"])):
            if ddpres[0]["deprel"][i] == "VV" and ddpres[0]["head"][i] == hednum:
                return {"sentInfo": sent, "jx": "连动句", "next_Class": ""}
            elif ddpres[0]["deprel"][i] == "DBL" and ddpres[0]["head"][i] == hednum:  #兼语句
                return {"sentInfo": sent, "jx": "兼语句", "next_Class": ""}
            elif lacres[0][i] == "把" and lacres[1][i] == "p":
                return {"sentInfo": sent, "jx": "把字句", "next_Class": ""}
            elif lacres[0][i] == "被" and lacres[1][i] == "p":
                return {"sentInfo": sent, "jx": "被字句", "next_Class": ""}
            elif lacres[0][i] == "是" and ddpres[0]["deprel"][i] == "HED":
                for j in range(len(ddpres[0]["deprel"])):
                    if ddpres[0]["word"][j] == "的" and ddpres[0]["deprel"][j] == "VOB" and ddpres[0]["head"][j] == hednum:
                        return {"sentInfo": sent, "jx": "是……的句", "next_Class": ""}
                return {"sentInfo": sent, "jx": "是字句", "next_Class": ""}


            elif lacres[0][i] == "有" and ddpres[0]["deprel"][i] == "HED":
                return {"sentInfo": sent, "jx": "有字句", "next_Class": ""}




            if ddpres[0]["deprel"][i] == "ATT" and ddpres[0]["head"][i] == hednum and lacres[1][hednum-1] == "u":  #我学计算机的
                return {"sentInfo": sent, "jx": "名词谓语句", "next_Class": "主||“的”字词组"}
            elif lacres[1][hednum-1] == "TIME":  #明天晴天
                return {"sentInfo": sent, "jx": "名词谓语句", "next_Class": "主||名词词组"}
            elif lacres[1][hednum-1] == "m" :  # 我十九岁：数量词组
                return {"sentInfo": sent, "jx": "名词谓语句", "next_Class": "主||数量词组"}
            elif lacres[1][hednum-1] == "n":
                return {"sentInfo": sent, "jx": "名词谓语句", "next_Class": "主||名词词组"}
            elif ddpres[0]["deprel"][i] == "VOB":  #这部电影我看过
                for j in range (len(ddpres[0]["deprel"])) :
                    if ddpres[0]["deprel"][j] == "SBV" and j > i :
                        return {"sentInfo": sent, "jx": "主谓谓语句", "next_Class": ""}
            elif ddpres[0]["deprel"][i] == "ATT" and lacres[1][i] == 'PER':  #VOB被识别成ATT的情况
                for j in range (len(ddpres[0]["deprel"])) :
                    if ddpres[0]["deprel"][j] == "SBV" and j > i :
                        return {"sentInfo": sent, "jx": "主谓谓语句", "next_Class": ""}

            elif ddpres[0]["deprel"][i] == "CMP" and ddpres[0]["head"][i] == hednum and lacres[1][hednum-1] == "a":  #他比我高一厘米
                return {"sentInfo": sent, "jx": "形容词谓语句", "next_Class": ""}
            elif ddpres[0]["deprel"][i] == "VOB" and ddpres[0]["head"][i] == hednum and lacres[1][i] == "v":
                return {"sentInfo": sent, "jx": "动词谓语句", "next_Class": ""}
        return {"sentInfo": sent, "jx": "", "sentClass": "单句"}# 不确定




if __name__ == '__main__':
    text = "宝迪康公司请求二审法院依法维护其合法权益"
    print(sent_ident(text))